<template>
	<view class="content">
		<view class="title" style="margin-top: 200rpx;">你的居住地是？</view>

		<picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view"
			mask-style="background:transparent;">
			<picker-view-column>
				<view class="item" :class="{ select: item == year }" v-for="(item, index) in provinces" :key="index">
					{{ item.province }}
				</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" :class="{ select: item == month }" v-for="(item, index) in citys" :key="index">
					{{ item.city }}
				</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" :class="{ select: item == day }" v-for="(item, index) in areas" :key="index">
					{{ item.name }}
				</view>
			</picker-view-column>
		</picker-view>

		<zy-register-bottom @next='next'></zy-register-bottom>
	</view>
</template>

<script>
	import RouteUtil from '@/main/common/RouteUtil.js';
	export default {
		data() {
			return {
				data: {
					sex: '',
					nick: '',
					birthday: '',
					heightId: '',
					weightId: '',
					careerId: '',
					incomeId: '',
					tagIds: '',
					educId: '',
					headPicId: '',
					prId: '',
					cityId: '',
					distId: '',
					passWord: '123456'
				},
				provinces: [],
				citys: [],
				areas: [],
				value: [0, 0, 0],
				indicatorStyle: `height: 50px;`,
				year: {},
				month: {},
				day: {}
			};
		},
		onLoad() {
			this.data = uni.getStorageSync('registerInfo');
			this.requestDict();
		},

		methods: {
			back() {
				uni.navigateBack();
			},
			async requestDict() {
				let res = await this.$common.post('/app/geren/sslist');
				if (0 == res.code) {
					this.provinces = res.data.list;
					this.citys = this.provinces[0].citiesList;
					this.areas = this.citys[0].areaList;
					this.data.prId = this.provinces[0].provinceid;
					this.data.cityId = this.citys[0].cityid;
					this.data.distId = this.areas[0].id;
					this.year = this.provinces[0];
					this.month = this.citys[0];
					this.day = this.areas[0];
				}
			},
			bindChange: function(e) {
				const val = e.detail.value;
				this.citys = this.provinces[val[0]].citiesList;
				this.areas = this.citys[val[1]].areaList;
				this.data.prId = this.provinces[val[0]].provinceid;
				this.data.cityId = this.citys[val[1]].cityid;
				this.data.distId = this.areas[val[2]].id;
				this.year = this.provinces[val[0]];
				this.month = this.citys[val[1]];
				this.day = this.areas[val[2]];
			},
			async next() {
				let params = {
					provinceid: this.data.prId,
					cityid: this.data.cityId,
					areaId: this.data.distId,
				}
				let res = await this.$common.post('/app/geren/saveaddress', params);
				if(0 == res.code){
					uni.setStorageSync('registerInfo', this.data);
					RouteUtil.toRegister7()
				}
			}
		}
	};
</script>

<style lang="scss">
	.content {
		width: 100wh;
		height: 100vh;
		margin: 0 50rpx;

		.title {
			font-weight: bold;
			font-size: 48rpx;
			color: #222;
		}

		.picker-view {
			width: 100%;
			height: 600rpx;
			margin: 0 auto;
		}

		.item {
			height: 50px;
			line-height: 50px;
			text-align: center;
			color: #999;
		}

		.item.select {
			color: #222;
			font-size: 36rpx;
			font-weight: 600;
		}
	}
</style>